package com.eastfair.datasync.handler;

import com.alibaba.fastjson.JSONObject;
import com.eastfair.datasync.entity.CanalData;
import com.eastfair.datasync.listener.SyncAbstract;
import com.eastfair.datasync.util.RomaTypeStatic;
import com.eastfair.datasync.util.RomaUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
public class ExhibitionSpaceSycnHandler<ExhibitionSpace> extends SyncAbstract<ExhibitionSpace> {
    @Value("${roma.url}")
    private String url;

    @Value("${roma.XHWID}")
    private String appId;

    @Value("${roma.XHWAPPKEY}")
    private String appKey;


    @Override
    public void executeInsert(CanalData canalData) {
        List<ExhibitionSpace> exhibitionList = canalData.getObjectList();
        log.info("insert is {}", JSONObject.toJSONString(exhibitionList));
        RomaUtil.executeHttp(url, canalData.getDataBase() + "_" + canalData.getTableName(), exhibitionList, appId, appKey);
    }

    @Override
    public void executeUpdate(CanalData canalData) {
        List<ExhibitionSpace> exhibitionList = canalData.getObjectList();
        log.info("executeUpdate is {}", JSONObject.toJSONString(exhibitionList));
        RomaUtil.executeHttp(url, canalData.getDataBase() + "_" + canalData.getTableName(), exhibitionList, appId, appKey);
    }

    @Override
    public void executeAlter(CanalData canalData) {
        List<ExhibitionSpace> exhibitionList = canalData.getObjectList();
        RomaUtil.executeHttp(url, canalData.getDataBase() + "_" + canalData.getTableName(), exhibitionList, appId, appKey);
    }
}
